//
//  GenCustomCell.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/3/13.
//  Copyright © 2017年 金橙云. All rights reserved.
//

#import "GenCustomCell.h"

@implementation GenCustomCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self createUI];
        UIImageView *lineImg = [[UIImageView alloc] init];
        lineImg.backgroundColor = [UIColor orangeColor];
        [self addSubview:lineImg];
        [lineImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(4, 40));
            make.left.mas_equalTo(self.mas_left).offset(10);
            make.top.equalTo(self.mas_top).offset(7);
        }];
        //头像
        _imgView = [[UIImageView alloc] init];
       // _imgView.backgroundColor = [UIColor redColor];
        _imgView.image = [UIImage imageNamed:@"nanshihui"];
        [self addSubview:_imgView];
        [_imgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(15, 16));
            make.left.equalTo(lineImg.mas_left).offset(10);
            make.top.equalTo(self.mas_top).offset(8);
        }];
        
        //客户姓名
        _nameLab = [[UILabel alloc] init];
        _nameLab.textColor = OverColor;
        _nameLab.font = [UIFont systemFontOfSize:14];
        _nameLab.textAlignment = NSTextAlignmentLeft;
        _nameLab.text = @"邹华涛";
       // _nameLab.backgroundColor = [UIColor yellowColor];
        [self addSubview:_nameLab];
        [_nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(60, 18));
            make.left.equalTo(_imgView.mas_right).offset(8);
            make.top.equalTo(self.mas_top).offset(8);
        }];
        //客户性别
        _sexLab = [[UILabel alloc] init];
        _sexLab.textColor = [UIColor blackColor];
        _sexLab.font = [UIFont systemFontOfSize:10];
        _sexLab.text = @"男 |";
        _sexLab.textAlignment = NSTextAlignmentLeft;
        [self addSubview:_sexLab];
        [_sexLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(20, 16));
            make.left.equalTo(_nameLab.mas_right).offset(8);
            make.top.equalTo(self.mas_top).offset(8);
        }];
        //来电客户OR来访客户
        _keLab = [[UILabel alloc] init];
        _keLab.textColor = [UIColor blackColor];
        _keLab.font = [UIFont systemFontOfSize:10];
        _keLab.textAlignment = NSTextAlignmentLeft;
        _keLab.text = @"来电客户";
        [self addSubview:_keLab];
        [_keLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(80, 16));
            make.left.equalTo(_sexLab.mas_right).offset(8);
            make.top.equalTo(self.mas_top).offset(8);
        }];
        //上次跟进时间
        _shiLab = [[UILabel alloc] init];
        _shiLab.textColor = [UIColor blackColor];
        _shiLab.font = [UIFont systemFontOfSize:10];
        _shiLab.text = @"上次跟进 | 2017-02-20";
        _shiLab.textAlignment = NSTextAlignmentLeft;
        [self addSubview:_shiLab];
        [_shiLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(200, 16));
            make.left.equalTo(self.mas_left).offset(35);
            make.top.equalTo(self.mas_bottom).offset(-20);
        }];
        //打电话按钮
        _callBtn = [[UIButton alloc] init];
        [_callBtn setBackgroundImage:[UIImage imageNamed:@"dianhuatubiao"] forState:0];
        [_callBtn addTarget:self action:@selector(callPhoneBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        _callBtn.mm_acceptEventInterval = 10;
        [self addSubview:_callBtn];
        [_callBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(25);
            make.left.equalTo(self.mas_right).offset(-50);
            make.top.equalTo(self.mas_top).offset(12);
        }];

        //电话号码
        _phoneNumber = [[UILabel alloc] init];
        [self addSubview:_phoneNumber];
        
    }
    return self;
}

-(void)setUpGenJinCellWIthName:(NSString *)_name withSex:(NSString *)_sex withVisit:(NSString *)_visit withLast:(NSString *)_last withPhone:(NSString *)_phone
{
    _nameLab.text = _name;
    _sexLab.text = _sex;
    _keLab.text = _visit;
    _shiLab.text = [NSString stringWithFormat:@"上次跟进 | %@",_last];
    _phoneNumber.text = _phone;
    
    
}
-(void)callPhoneBtnClick:(UIButton *)btn
{
    NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"tel:%@",_phoneNumber.text];
    UIWebView *callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self addSubview:callWebview];
}
- (void)createUI{
    //创建一个UIView比self.contentView小一圈
    self.bgView  = [[UIView alloc] initWithFrame:CGRectMake(10,4, SCREEN_WIDTH-10*2, 44)];
    self.bgView.backgroundColor = [UIColor whiteColor];
    //给bgView边框设置阴影
    self.bgView.layer.shadowOffset = CGSizeMake(2,2);
    self.bgView.layer.shadowOpacity = 0.3;
    self.bgView.layer.shadowColor = [UIColor blackColor].CGColor;
    [self.contentView addSubview:self.bgView];
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
